package org.agony2d.gpu {
	import flash.utils.ByteArray;
	
	import org.agony2d.core.agony_internal;
	import org.agony2d.gpu.core.GroupAA;
	import org.agony2d.gpu.supportClasses.buffers.BuffersManager;
	
	use namespace agony_internal;
	
	/** [ BatchGroupAA ]
	 *  [◆]
	 *  	1.  needBatchUpdated
	 *  [★]
	 *  	a.  批处理型GroupAA，子NodeAA不可包含GroupAA，可手动更新(使用◆reset)...
	 */
public class BatchGroupAA extends GroupAA {
	
    public function BatchGroupAA( fullTexName:String, tinted:Boolean = false, smoothing:Boolean = false ) {
		this.setting(fullTexName, tinted, smoothing)
		m_bytes = new ByteArray
		m_needBatchUpdated = true
    }
	
	final public function get needBatchUpdated() : Boolean {
		return m_needBatchUpdated
	}
	
	public function set needBatchUpdated( b:Boolean ) : void {
		m_needBatchUpdated = true
	}
	
	[Inline]
	final override agony_internal function render( vertexChanged:Boolean ) : void {
		if (m_numNodes > 0 && !m_invisible) {
			this.doFinishPrevGroup()
			BuffersManager.g_currGroup    =  this
			BuffersManager.g_currFullTex  =  m_fullTex
			BuffersManager.g_currProgram  =  m_program
			if (m_needBatchUpdated) {
				this.doExtractNodes(vertexChanged)
				m_bytes.length = 0
				m_bytes.writeBytes(BuffersManager.g_bytes)
				m_needBatchUpdated = false
			}
			else {
				BuffersManager.g_bytes.writeBytes(m_bytes)
			}
			BuffersManager.goFinishAll()
			this.doResumePrevGroup()
		}
	}
	
	agony_internal var m_needBatchUpdated:Boolean
	agony_internal var m_bytes:ByteArray
}
}